﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Urbania.GUI.Elements
{
    public class RightClickScreenObject : SelectableScreen
    {
        protected string text;
        protected string script;
        protected Color textColor;

        public string Text { get { return this.text; } }

        public RightClickScreenObject(string text)
        {
            this.text = text;
            this.script = null;
            this.textColor = Color.White;
        }

        public RightClickScreenObject(string text, string scriptFile)
        {
            this.text = text;
            this.script = scriptFile;
            this.textColor = Color.White;
        }

        public void Update(GameTime gameTime, object o, RightClickMenu r)
        {
            base.Update();

            if(this.mouseIsIn)
                this.textColor = Color.Yellow;
            else
                this.textColor = Color.White;

            if (this.mouseClickingOn)
            {
                this.OnClick(o);
                r.Remove();
            }
        }

        public void Draw(Vector2 position, SpriteFont font, SpriteBatch spriteBatch)
        {
            this.bounds = new Rectangle((int)position.X, (int)position.Y, (int)font.MeasureString(this.text).X,
                (int)font.MeasureString(this.text).Y);
            spriteBatch.DrawString(font, text, position, textColor);
        }

        public void OnClick(object o)
        {
            if (this.script != null)
                Program.lua.LuaVirtual.DoFile(Utilities.Loader.GetScriptFile(script));
        }
    }
}
